package org.daochong.fastdev;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.daochong.lang.JdbcTemplate;
import org.daochong.lang.Page;
import org.daochong.lang.PageResult;

public class DefaultJdbcOperations implements JdbcOperations {

	private JdbcTemplate jdbc;

	public JdbcTemplate getJdbc() {
		return jdbc;
	}

	public void setJdbc(JdbcTemplate jdbc) {
		this.jdbc = jdbc;
	}

	protected JdbcTemplate jdbc() {
		return jdbc;
	}

	public Object value(String sqlId, Map<String, Object> params) throws SQLException {
		JdbcTemplate jdbc = jdbc();
		return jdbc.firstValue(sqlId, params);
	}

	public Object get(String sqlId, Map<String, Object> params) throws SQLException {
		JdbcTemplate jdbc = jdbc();
		return jdbc.firstMap(sqlId, params);
	}

	public List<Map<String, Object>> list(String sqlId, Map<String, Object> params) throws SQLException {
		JdbcTemplate jdbc = jdbc();
		return jdbc.listObjects(sqlId, params);
	}

	public PageResult<Map<String, Object>> page(Page page, String sqlId, Map<String, Object> params)
			throws SQLException {
		JdbcTemplate jdbc = jdbc();
		return jdbc.listObjects(page, sqlId, params);
	}

	public int exec(String sqlId, Map<String, Object> params) throws SQLException {
		JdbcTemplate jdbc = jdbc();
		return jdbc.execute(sqlId, params);
	}

}
